﻿using Admin.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Admin.Controllers
{
    public class GoodsController : ApiController
    {
        // GET: api/Goods
        [HttpGet]
        public IHttpActionResult GetList(string StudentName, int page = 1, int limit = 10)
        {
            using (CRMEntities db = new CRMEntities())
            {
                var datalist = db.Netfollows.AsEnumerable();
                if (!string.IsNullOrEmpty(StudentName))
                {
                    datalist = datalist.Where(p => p.StudentName.Contains(StudentName));
                }
                var count = datalist.Count();
                var list = datalist.Select(p => new {
                    Id = p.Id,
                    StudentName = p.StudentName,
                    FollowTime = p.FollowTime.ToString(),
                    NextFollowTime = p.NextFollowTime.ToString(),
                    Content1 = p.Content1,
                    FollowType = p.FollowType,
                    FollowState = p.FollowState
                }).Skip((page - 1) * limit).Take(limit).ToList();
                return Json(new { count = count, data = list });
            }
        }
    }
}
